// 算法配置DTO接口
import request from "../../utils/request";
import {ApiResponse} from "./text";

export interface AlgorithmConfigDTO {
    algorithmId?: number;
    algorithmName: string;
    name: string;
    description?: string;
    caseSensitive: boolean;
    ignoreWhitespace: boolean;
    normalizeText: boolean;
    isActive: number;
    additionalParams?: Record<string, any>;
}

// API响应接口
interface BaseResponse<T> {
    code: number;
    message: string;
    data: T;
}

// 算法配置VO接口
export interface AlgorithmConfigVO {
    algorithmId: number;
    name: string;
    algorithmName: string;
    caseSensitive: boolean;
    ignoreWhitespace: boolean;
    normalizeText: boolean;
    additionalParams?: Record<string, any>;
    isActive: number;
    description?: string;
    creatorId?: number;
    createdAt: string;
    updatedAt: string;
}

// 分页响应接口
interface PageResponse<T> {
    records: T[];
    total: number;
    size: number;
    current: number;
    pages: number;
}



// 查询参数接口
export interface AlgorithmQueryParams {
    current?: number;
    size?: number; // 修改这里，将 pageSize 改为 size
    name?: string;
    algorithmName?: string;
    isActive?: number;
}



export const algorithmApi = {
    // 创建算法配置
    createAlgorithmConfig: async (data: AlgorithmConfigDTO) => {
        return request.post<BaseResponse<boolean>>('/api/algorithm', data);
    },

    // 获取算法配置列表
    getAlgorithmList: async (params: AlgorithmQueryParams) => {
        const response = await request.get<ApiResponse<PageResponse<AlgorithmConfigVO>>>('/api/algorithm/list', {
            params: {
                ...params,
                size: params.size // 确保使用 size 参数
            }
        });
        return response.data;
    },

    // 获取算法配置详情
    getAlgorithmDetail: async (algorithmId: number) => {
        const  response = await request.get<ApiResponse<AlgorithmConfigVO>>(`/api/algorithm/${algorithmId}`);
        return response.data;
    },

    // 更新算法配置
    updateAlgorithm: async (data: Partial<AlgorithmConfigVO>) => {
        const response= await request.put<ApiResponse<boolean>>('/api/algorithm/update', data);
        return response.data;
    },

    // 删除算法配置
    deleteAlgorithm: async (algorithmId: number) => {
        const  response = await  request.delete<ApiResponse<boolean>>(`/api/algorithm/${algorithmId}`);
        return response.data;
    }
};
